import { fallbackRequestGet, fallbackRequestPost } from '@/utils/Request'

/**
 * 请求前缀，后面后台添加网关后需要前缀选择微服务
 */
const URL_PREFIX = 'middle-goods/'

/**
 * 用户调用，根据订单号查询物流信息
 * @param {String|Number} orderId 订单id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryTranceByOrderIdUser = (orderId, successCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'good_deliver/queryTranceByOrderIdUser', { orderId }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 用户调用，根据订单号收货
 * @param {String|Number} orderId 订单id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const takeDeliveryByOrderId = (orderId, successCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'good_deliver/takeDeliveryByOrderId', { orderId }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 用户调用，根据订单号收货，批量处理
 * @param {Array<String|Number>} orderIds 订单id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const takeDeliveryByOrderIds = (orderIds, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_deliver/takeDeliveryByOrderIds', orderIds, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}
